package com.dove.controller;

import java.util.Map;

import javax.servlet.ServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.dove.common.MyProperties;
import com.dove.utils.DemoUtil;

/**
 * 
 * @description 支付宝接口 - 与用户有关的
 * @author 创建人:dxw
 * @date 时间：2021年6月3日-下午2:02:33
 * @version 1.0.0
 *
 */
@RestController
@RequestMapping("/notify")
public class NotifyController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());
	@Autowired
	private MyProperties myProperties;

	/**
	 * 
	 * @description gateway（用一句话描述这个变量表示什么）
	 * @author 创建人：dxw
	 * @date 时间：2021年6月4日-下午6:17:43
	 * @param accessToken
	 * @return String
	 * @exception @since 1.0.0
	 */
	@PostMapping("/gateways")
	public String gateways(final ServletRequest request) {
		// 获取支付宝POST过来反馈信息
		// 
		Map<String, String> params = DemoUtil.requestToParamsMap(request);
		logger.info("/gateways" + JSON.toJSONString(params));
		try {
			boolean flag = AlipaySignature.rsaCheckV1(params, myProperties.getAlipay_public_key(), "UTF-8", "RSA2");
			if (flag) {
				
			} else {
				logger.error("gateways - 网关验签失败" + params);
			}
		} catch (AlipayApiException e) {
			logger.error("gateways - 网关通知异常" + e);
		}
		return "success";
	}


}